********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global controls "lncrefin dT7exlnassets dT7excashas"
global regcommands ", pool(5) absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019long, case(lower)
run RO_creditregister tm(2016m2) tm(2020m2) 0
keep bankid borrowerid time disbur 

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(e14 dtop66e14 dmid6633e14 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2016m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)
gen mnth =month((dofm(time)))
gen jan=(mnth==1)
gen feb=(mnth==2)
gen mar=(mnth==3)
gen apr=(mnth==4)
gen may=(mnth==5)
gen jun=(mnth==6)
gen jul=(mnth==7)
gen sep=(mnth==9)
gen oct=(mnth==10)
gen nov=(mnth==11)
gen dec=(mnth==12)
drop mnth
foreach x in jan feb mar apr may jun jul sep oct nov dec {
gen `x'dtop66e14=`x'*dtop66e14
gen `x'dmid6633e14=`x'*dmid6633e14
gen `x'e14=`x'*e14
}
run RO_tdummies 2019 1
run RO_tdintera 1 "e14 dtop66e14 dmid6633e14 exlnassets excashas"

reghdfe $y jane14 febe14 mare14 apre14 maye14 june14 jule14 sepe14 octe14 nove14 dece14 dT7e14 $controls $regcommands

**# Bookmark (output - columns 1 and 2)
est clear
cd $outputdirectory
reghdfe $y jane14 febe14 mare14 apre14 maye14 june14 jule14 sepe14 octe14 nove14 dece14 dT7e14 $controls $regcommands
est save TABIIG_C1234 
reghdfe $y jandtop66e14 febdtop66e14 mardtop66e14 aprdtop66e14 maydtop66e14 jundtop66e14 juldtop66e14 sepdtop66e14 octdtop66e14 novdtop66e14 decdtop66e14 jandmid6633e14 febdmid6633e14 mardmid6633e14 aprdmid6633e14 maydmid6633e14 jundmid6633e14 juldmid6633e14 sepdmid6633e14 octdmid6633e14 novdmid6633e14 decdmid6633e14 dT7dtop66e14 dT7dmid6633e14 $controls $regcommands
est save TABIIG_C1234, append
cd ..

********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global controls "lncrefin dT7exlnassets dT7excashas"
global regcommands ", pool(5) absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2012m6) tm(2016m6) 0
keep bankid borrowerid time disbur 

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e10 e13 dtop85e13 exlnassets excashas)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2012m7)&time<=tm(2016m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

run RO_tdummies 2015 1
run RO_tdintera 1 "e13 dtop85e13 exlnassets excashas"
gen mnth =month((dofm(time)))
gen jan=(mnth==1)
gen feb=(mnth==2)
gen mar=(mnth==3)
gen apr=(mnth==4)
gen may=(mnth==5)
gen jun=(mnth==6)
gen jul=(mnth==7)
gen ago=(mnth==8)
gen sep=(mnth==9)
gen oct=(mnth==10)
gen nov=(mnth==11)
drop mnth
foreach x in jan feb mar apr may jun jul ago sep oct nov {
gen `x'dtop85e13=`x'*dtop85e13
gen `x'e13=`x'*e13
}

**# Bookmark (output - columns 3 and 4)
est clear
cd $outputdirectory
reghdfe $y jane13 febe13 mare13 apre13 maye13 june13 jule13 agoe13 sepe13 octe13 nove13 dT7e13 $controls $regcommands
est save TABIIG_C1234, append
reghdfe $y jandtop85e13 febdtop85e13 mardtop85e13 aprdtop85e13 maydtop85e13 jundtop85e13 juldtop85e13 agodtop85e13 sepdtop85e13 octdtop85e13 novdtop85e13 dT7dtop85e13 $controls $regcommands
est save TABIIG_C1234, append
cd ..





